home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CNUMBERE
/
CNUMBERE.C
next >
Wrap
Text File
|
1991-07-04
|
5KB
|
241 lines
/* Methods for CNumberEditor */
#include "CNumberEditor.h"
#include "SANE.h"
extern CBureaucrat *gGopher;
extern CursHandle gIBeamCursor;
extern short gClicks;
static CNumberEditor *gNumberEditor;
void CNumberEditor::INumberEditor(CView *anEnclosure, CBureaucrat *aSupervisor,
Str255 aFontName, int aFontSize,
Rect *aRect, short sigDigs,long setComm)
{
Rect stringRect;
short aWidth, aHeight;
aWidth=aRect->right-aRect->left;
aHeight=aRect->bottom-aRect->top;
inherited::IPane(anEnclosure, aSupervisor,aWidth, aHeight,aRect->left, aRect->top,
sizFIXEDSTICKY, sizFIXEDSTICKY);
wantsClicks=TRUE;
dirty=FALSE;
significantDigits=sigDigs;
GetFNum(aFontName, &(itsStyle.tsFont));
if(aFontSize==0)
{
if(sigDigs<0)
aFontSize=.7*aHeight;
else
aFontSize=aHeight-3;
}
else
{
if(sigDigs<0)
aFontSize=(aFontSize>(0.7*aHeight))?(0.7*aHeight):aFontSize;
else
aFontSize=(aFontSize>(aHeight-3))?(aHeight-3):aFontSize;
}
itsStyle.tsSize=aFontSize;
SetCommandNumber=setComm;
stringRect=frame;
stringRect.left+=1;stringRect.right-=1;stringRect.top+=1;stringRect.bottom-=2;
this->Prepare();
itsTEHandle=TEStylNew(&stringRect, &stringRect);
TESetStyle(doFont+doSize, &itsStyle, TRUE, itsTEHandle);
TEAutoView(FALSE, itsTEHandle);
(*itsTEHandle)->just=teJustLeft;
TECalText(itsTEHandle);
}
void CNumberEditor::Dispose(void)
{
TEDispose(itsTEHandle);
inherited::Dispose();
}
void CNumberEditor::SetString(Str255 aString)
{
Ptr aPointer;
long numCharacters;
aPointer=(Ptr)aString;
aPointer+=1;
numCharacters=(long)aString[0];
TESetText(aPointer, numCharacters, itsTEHandle);
this->SelectAll();
this->Refresh();
}
void CNumberEditor::GetString(Str255 aString)
{
register int i;
Handle text;
long size;
text=(*itsTEHandle)->hText;
size=GetHandleSize(text);
for(i=0;i<size;i++)
aString[i]=((char*)(*text))[i];
aString[size]='\0';
CtoPstr(aString);
}
void CNumberEditor::SelectAll(void)
{
int aLength;
aLength=(*itsTEHandle)->teLength;
this->Prepare();
TESetSelect(0, aLength, itsTEHandle);
TESetStyle(doFont+doSize, &itsStyle, FALSE, itsTEHandle);
TECalText(itsTEHandle);
}
double CNumberEditor::GetDoubleValue(void)
{
Str255 aString;
double value, *doublePtr;
extended num80;
DecForm aFormat;
this->GetString(aString);
num80=str2num(aString);
if(sizeof(double)==12)
x80tox96(&num80,&value);
else
{
doublePtr=(double*)(&num80);
value=*doublePtr;
}
aFormat.style = FLOATDECIMAL;
aFormat.digits = significantDigits;
num2str(&aFormat, num80, aString);
this->SetString(aString);
dirty=FALSE;
return value;
}
void CNumberEditor::SetDoubleValue(double newValue)
{
Str255 aString;
extended num80, *num80Ptr;
DecForm aFormat;
aFormat.style = FLOATDECIMAL;
aFormat.digits = significantDigits;
if(sizeof(double)==12)
{
x96tox80(&newValue,&num80);
num2str(&aFormat, num80, aString);
}
else
{
num80Ptr=(extended*)(&newValue);
num2str(&aFormat, *num80Ptr, aString);
}
this->SetString(aString);
dirty=FALSE;
}
long CNumberEditor::GetLongValue(void)
{
long value;
Str255 aString;
this->GetString(aString);
StringToNum(aString, &value);
NumToString(value,aString);
this->SetString(aString);
dirty=FALSE;
return value;
}
void CNumberEditor::SetLongValue(long newValue)
{
Str255 aString;
dirty=FALSE;
NumToString(newValue,aString);
this->SetString(aString);
}
void CNumberEditor::Draw(Rect *area)
{
FrameRect(&frame);
TEUpdate(area, itsTEHandle);
}
void CNumberEditor::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
{
if((theChar==13)||(theChar==3))
{
itsSupervisor->DoCommand(SetCommandNumber);
this->SelectAll();
dirty=FALSE;
}
else
{
dirty=TRUE;
this->Prepare();
TEKey(theChar, itsTEHandle);
}
}
void CNumberEditor::DoClick(Point hitPt, short modifierKeys, long when)
{
if(gClicks==2)
this->SelectAll();
else
TEClick(hitPt, FALSE, itsTEHandle);
}
void CNumberEditor::AdjustCursor(Point where, RgnHandle mouseRgn)
{
SetCursor(*gIBeamCursor);
gGopher=this;
if(gNumberEditor!=this)
{
this->Activate();
this->SelectAll();
}
}
void CNumberEditor::Dawdle(long *sleep)
{
Prepare();
TEIdle(itsTEHandle);
*sleep = GetCaretTime();
}
void CNumberEditor::Activate(void)
{
inherited::Activate();
if(gNumberEditor)
gNumberEditor->Deactivate();
gNumberEditor=this;
gGopher=this;
this->Prepare();
TEActivate(itsTEHandle);
}
void CNumberEditor::Deactivate(void)
{
inherited::Deactivate();
this->Prepare();
TEDeactivate(itsTEHandle);
gNumberEditor=0L;
}